<?php

	$input = $_GET["input"];
	
	$pattern = "/^[-\+]?[\d]+[.]?[\d]*([-\/\+\*][-\+]?[\d]+[.]?[\d]*)*$/";
	if (preg_match($pattern,$input,$matches)) {
		echo "Pattern matched = ".$matches[0]."<br/><br/>";					
		$error1 = "/(\/[0]+[.]?[0]*[-\/\+\*]|(\/[0]+[.]?[0]*$)|--|\+\+)/";
		if (preg_match($error1,$input,$matchedError)) {
			echo "Invalid expression. Error ( ".$matchedError[0]." )";
		}
		else {
			eval("\$answer = $input;");
			echo $input." = ".$answer."\n";
		}
	}	
	else {
		echo "Invalid expression";
	}

// check for 0/0 and 1--3
?>

